package your.pack.sten;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class ClickedPage extends Activity {
	private WebView wv;
	final Activity activity = this; 
	String url;
	String newsPage = "http://m.sten.or.kr/bbs/board.php?bo_table=news";
	String teststoryPage = "http://m.sten.or.kr/bbs/board.php?bo_table=test_story";
	String glossaryPage = "http://dic.sten.or.kr/";
	String freePage = "http://m.sten.or.kr/bbs/board.php?bo_table=free";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_PROGRESS); 		
		setContentView(R.layout.webview);
		
		Intent intent = getIntent(); 
		String str = intent.getStringExtra("selectedPage");
		
		if (str.equals("news"))
			url = newsPage;
		else if (str.equals("teststory"))
			url = teststoryPage;
		else if (str.equals("glossary"))
			url = glossaryPage;
		else if (str.equals("free"))
			url = freePage;
			
		wv = (WebView)findViewById(R.id.glossary);
		wv.getSettings().setJavaScriptEnabled(true);	 
		wv.setWebChromeClient(new WebChromeClient() {
		   public void onProgressChanged(WebView view, int progress) {
		       activity.setProgress(progress * 100);
		   } 
		});
		wv.setWebViewClient(new WebViewClient() {
		    public void onReceivedError(WebView view, int errorCode, String description, String fallingUrl) {
		        Toast.makeText(activity, "Opps! Error Occurs!"+description, Toast.LENGTH_SHORT).show();
		    }
		});		
		wv.loadUrl(url);
		wv.setWebViewClient(new WebViewClient(){
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
	       		view.loadUrl(url);
	       		return true;
			}
		});		
	}	
}
